package com.ibuu.demos.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ibuu.demos.mapper.NewsMapper;
import com.ibuu.demos.pojo.News;
import com.ibuu.demos.service.NewsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

    @Autowired
    private NewsMapper newsMapper;


    @Override
    public Page<News> getNews() {
        Page<News> newsPage = new Page<>();
        Page<News> newsPage1 = newsMapper.selectPage(newsPage, null);
        return newsPage1;
    }
//添加news
    @Override
    public String publishNews(News news) {
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
        String time = sdf.format(date);
        news.setDate(time);
        Random r = new Random();
        int i = r.nextInt(100);
        news.setId(i);
        newsMapper.insert(news);
        return "success";
    }
}
